from django.contrib import admin
from course.models import CourseDirectionModel, CourseCategoryModel, CourseModel, TeacherModel, ActivateModel, DiscountModel, DiscountTypeModel, CourseActivateModel


# 注册模型类
# 自定义管理页面

# 自定义外键关联模型类
# admin.TabularInline  让外键对应的数据   横向排列
# admin.StackedInline  让外键对应的数据   垂直纵向排列


class CourseCategoryInLine(admin.TabularInline):
    model = CourseCategoryModel
    fields = ['id', 'name', 'orders']


class CourseDirectionModelAdmin(admin.ModelAdmin):
    list_display = ['id', 'name']
    inlines = [CourseCategoryInLine]


class CourseCategoryModelAdmin(admin.ModelAdmin):
    list_display = ['id', 'name']


class CourseModelAdmin(admin.ModelAdmin):
    list_display = ['id', 'name', 'price', 'direction', 'category', 'teacher', 'course_cover_small']
    ordering = ['id']
    search_fields = ['name']
    list_filter = ['recomment_home_hot', 'recomment_home_top']


class TeacherModelAdmin(admin.ModelAdmin):
    list_display = ['id', 'name', 'avatar_small']


class ActivateModelAdmin(admin.ModelAdmin):
    list_display = ['id', 'name', 'start_time', 'end_time', 'description']


class DiscountTypeModelAdmin(admin.ModelAdmin):
    list_display = ['id', 'name', 'remark']


class DiscountModelAdmin(admin.ModelAdmin):
    list_display = ['id', 'name', 'discount_type', 'condition', 'sale']


class CourseActivateModelAdmin(admin.ModelAdmin):
    list_display = ['id', 'name', 'activate', 'course', 'discount']


admin.site.register(CourseDirectionModel, CourseDirectionModelAdmin)
admin.site.register(CourseCategoryModel, CourseCategoryModelAdmin)
admin.site.register(CourseModel, CourseModelAdmin)
admin.site.register(TeacherModel, TeacherModelAdmin)
admin.site.register(ActivateModel, ActivateModelAdmin)
admin.site.register(DiscountTypeModel, DiscountTypeModelAdmin)
admin.site.register(DiscountModel, DiscountModelAdmin)
admin.site.register(CourseActivateModel, CourseActivateModelAdmin)
